package com.gxa.meiye.admin.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.meiye.admin.platform.mapper.TherapisthMapper;
import com.gxa.meiye.admin.platform.pojo.vo.TherapistVo;
import com.gxa.meiye.admin.platform.pojo.vo.UpdateTherapistStatusVo;
import com.gxa.meiye.admin.platform.service.TherapistddService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TherapistddServiceImpl extends ServiceImpl<TherapisthMapper, TherapistVo> implements TherapistddService {
    @Autowired
    private TherapisthMapper therapistMapper;

    @Override
    public List<TherapistVo> selectTherapistList() {
        List<TherapistVo> therapistVos = therapistMapper.selectList(null);
        for (TherapistVo therapistVo : therapistVos){
            if(therapistVo.getStatus()!=0){
                therapistVo.setStatus(1);
            }
        }
        return therapistVos;
    }

    @Override
    public void updateStatus(UpdateTherapistStatusVo therapistStatusVo) {
        LambdaUpdateWrapper<TherapistVo> therapistVoLambdaUpdateWrapper = Wrappers.lambdaUpdate();
        therapistVoLambdaUpdateWrapper.eq(TherapistVo::getId,therapistStatusVo.getId());
        if(therapistStatusVo.getStatus()!=0) {
            therapistVoLambdaUpdateWrapper.set(TherapistVo::getStatus, 0);
        }else {
            therapistVoLambdaUpdateWrapper.set(TherapistVo::getStatus, 1);
        }
        therapistMapper.update(null,therapistVoLambdaUpdateWrapper);
    }

    @Override
    public List<TherapistVo> selectTherapists(String select) {
        LambdaQueryWrapper<TherapistVo> therapistVoLambdaQueryWrapper = Wrappers.lambdaQuery();
        therapistVoLambdaQueryWrapper.like(TherapistVo::getId,"%"+select+"%").or().like(TherapistVo::getName,"%"+select+"%")
                .or().like(TherapistVo::getPhone,"%"+select+"%");
        List<TherapistVo> therapistVos = therapistMapper.selectList(therapistVoLambdaQueryWrapper);
        return therapistVos;
    }
}
